<template>
  <div class="fx-block">
    <div class="toggle">
      <div>
        <input type="checkbox" id="onoff-switch" v-model="checked" />
        <div data-unchecked="On" data-checked="Off"></div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';
const checked = ref(false);
</script>

<style scoped>
.toggle > div {
  position: relative;
  padding: 10px;
  width: 150px;
  height: 75px;
  border-radius: 50px;
  box-shadow: 0 -1px 1px 0 rgba(0, 0, 0, .5), 0px 1px 1px 0 rgba(255, 255, 255, 1);
  background: linear-gradient(to bottom, #bdbfc1 0%, #f9fbfe 100%);
}
.toggle > div > input[type=checkbox] {
  position: absolute;
  opacity: 0;
  top: -3px;
  left: 17px;
  width: 130px;
  height: 55px;
  z-index: 5;
  margin: 0;
}
.toggle > div > input[type=checkbox] ~ div {
  width: 130px;
  height: 55px;
  border-radius: 50px;
  border: 1px solid #979797;
  box-shadow: inset 5px 0 0 0 rgba(0, 0, 0, .1), inset -5px 0 0 0 rgba(0, 0, 0, .1), inset -6px 0 0 0 rgba(255, 255, 255, .5), inset -4px 6px 11px -5px rgba(0, 0, 0, .2), inset 1px 1px 0 0 rgba(255, 255, 255, 1), -6px 4px 11px -7px rgba(0, 0, 0, .5);
  background: linear-gradient(to right, #fdfcfb 37%, #e5e5e5 61%);
}
.toggle > div > input[type=checkbox]:checked ~ div {
  box-shadow: inset -5px 0 0 0 rgba(0, 0, 0, .1), inset 5px 0 0 0 rgba(0, 0, 0, .1), inset 6px 0 0 0 rgba(255, 255, 255, .5), inset -4px 6px 11px -5px rgba(0, 0, 0, .2), inset 1px 1px 0 0 rgba(255, 255, 255, 1), -6px 4px 11px -7px rgba(0, 0, 0, .5);
  background: linear-gradient(to right, #e5e5e5 39%, #fdfcfb 63%);
}
.toggle > div > input[type=checkbox] ~ div:before {
  content: attr(data-unchecked);
  display: block;
  position: absolute;
  border-radius: 10px;
  top: 27px;
  left: 30px;
  color: #119400;
  text-shadow: 0 1px 0 #fff, 0px 0 7px #007a08;
  filter: dropshadow(color=#007a08, offx=0, offy=0);
  transition: color 0.3s;
}
.toggle > div > input[type=checkbox] ~ div:after {
  content: attr(data-checked);
  color: #df0000;
  text-shadow: 0 1px 0 #fff, 0px 0 7px #df0000;
  filter: dropshadow(color=#df0000, offx=0, offy=0);
  display: block;
  position: absolute;
  border-radius: 10px;
  top: 27px;
  left: 100px;
  transition: color 0.3s;
}
.toggle > div > input[type=checkbox]:checked ~ div:before {
  color: #000;
  text-shadow: none;
  filter: dropshadow(none);
}
.toggle > div > input[type=checkbox]:checked ~ div:after {
  color: #119400;
  text-shadow: 0 1px 0 #fff, 0px 0 7px #007a08;
  filter: dropshadow(color=#007a08, offx=0, offy=0);
}
/* 暗色主题适配 */
:deep(.dark) .toggle > div {
  background: linear-gradient(to bottom, #23232a 0%, #23232a 100%);
  box-shadow: 0 -1px 1px 0 #111, 0px 1px 1px 0 #333;
}
:deep(.dark) .toggle > div > input[type=checkbox] ~ div {
  background: linear-gradient(to right, #23232a 37%, #18181c 61%);
  border: 1px solid #444;
}
:deep(.dark) .toggle > div > input[type=checkbox]:checked ~ div {
  background: linear-gradient(to right, #18181c 39%, #23232a 63%);
  border: 1px solid #444;
}
:deep(.dark) .toggle > div > input[type=checkbox] ~ div:before {
  color: #3de1ff;
  text-shadow: 0 1px 0 #fff, 0px 0 7px #1fa2ff;
}
:deep(.dark) .toggle > div > input[type=checkbox] ~ div:after {
  color: #ff5c5c;
  text-shadow: 0 1px 0 #fff, 0px 0 7px #ff5c5c;
}
:deep(.dark) .toggle > div > input[type=checkbox]:checked ~ div:before {
  color: #fff;
  text-shadow: none;
}
:deep(.dark) .toggle > div > input[type=checkbox]:checked ~ div:after {
  color: #3de1ff;
  text-shadow: 0 1px 0 #fff, 0px 0 7px #1fa2ff;
}
</style> 